#include "messageCommonEx.h"
#include "common.h"
#include "networkessential.h"

messageCommonEx::messageCommonEx(const std::string &sender, 
		const std::string &groupname, unsigned int type)
:messageBase(type),
 m_sender(sender),
 m_groupname(groupname)
{}

void messageCommonEx::generateMessage(std::string &buf) const
{
	// Message content :
	// messagetype message_len invitername_len invitername groupname_len groupname

	unsigned int messagetype = m_messagetype;
	int message_len;
	int sendername_len = m_sender.size();
	int groupname_len   = m_groupname.size();

	message_len = sendername_len + groupname_len + 2 * IntLength;

	buf.append(FourBytesToNetChar(messagetype), IntLength);
	buf.append(FourBytesToNetChar(message_len), IntLength);
	buf.append(FourBytesToNetChar(sendername_len), IntLength);
	buf.append(m_sender);
	buf.append(FourBytesToNetChar(groupname_len), IntLength);
	buf.append(m_groupname);
}
